﻿//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;
//using Nb.Common;
//using Nb.Tools.DbManager.Libs.Backups;

//namespace Nb.Tools.DbManager.Libs
//{
//    public class OperationFacade
//    {
//        private readonly BackupService _backupService;

//        public OperationFacade(BackupService backupService)
//        {
//            _backupService = backupService;
//        }
        
//        #region backupdb

//        public bool IsCurrentOperationBackuped()
//        {
//            var currentOperationFolder = getCurrentOperationFolder();
//            var readValidateDbResult = ReadValidateDbResult();
//            var bakFilePath = currentOperationFolder.GetCurrentBackupFilePath();
//            return File.Exists(bakFilePath);
//        }

//        public IList<BackupFile> ListAllBackupFiles()
//        {
//            var currentOperationFolder = getCurrentOperationFolder();
//            var listAllBackupFiles = _backupService.ListAllBackupFiles(currentOperationFolder.Backups);
//            return listAllBackupFiles;
//        }

//        public MessageResult BackupDb()
//        {
//            var currentOperationFolder = getCurrentOperationFolder();
//            var readValidateDbResult = ReadValidateDbResult();
//            var bakFilePath = currentOperationFolder.GetCurrentBackupFilePath();
//            if (File.Exists(bakFilePath))
//            {
//                MyIOHelper.DeleteFile(bakFilePath);
//            }
//            var messageResult = _backupService.BackupDb(readValidateDbResult.DbName, readValidateDbResult.DbName, bakFilePath);
//            return messageResult;
//        }

//        public MessageResult RestoreDb(BackupFile backupFile)
//        {
//            var readValidateDbResult = ReadValidateDbResult();
//            var messageResult = _backupService.RestoreDb(readValidateDbResult.DbName, readValidateDbResult.DbName, backupFile.FilePath);
//            return messageResult;
//        }

//        public bool IsDbBackuped()
//        {
//            var fileResult = ReadBackupDbResult();
//            if (fileResult == null)
//            {
//                return false;
//            }

//            return true;
//        }

//        public BackupDbResult ReadBackupDbResult()
//        {
//            var operationFolder = OperationFolder.CurrentOperationFolder;
//            var currentBackupFilePath = operationFolder.GetCurrentBackupFilePath();
//            var fileResult = operationFolder.ReadResultFile<BackupDbResult>(currentBackupFilePath);
//            return fileResult;
//        }

//        public void SaveBackupDbResult()
//        {
//            var operationFolder = OperationFolder.CurrentOperationFolder;
//            var currentBackupFilePath = operationFolder.GetCurrentBackupFilePath();
//            var backupDbResult = new BackupDbResult() { CreatedAt = DateTime.Now, FilePath = currentBackupFilePath };
//            operationFolder.SaveResultFile(operationFolder.Version_02BackupDbResult, backupDbResult);
//        }

//        #endregion
//    }
//}
